package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.BusinessCardConfig;
import com.sc.nft.entity.dto.BusinessCardConfirmDTO;
import com.sc.nft.entity.vo.BusinessCardSetVO;
import com.sc.nft.mapper.BusinessCardConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class BusinessCardConfigDao extends ServiceImpl<BusinessCardConfigMapper, BusinessCardConfig> {

    /**
     * 该配置只会有一条.
     * @return
     */
    public BusinessCardConfig getBusinessCardConfig() {
        LambdaQueryWrapper<BusinessCardConfig> wrapper = Wrappers.lambdaQuery();
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public BusinessCardConfirmDTO getBusinessCardConfirm(Long userId) {
        return this.baseMapper.getBusinessCardConfirm(userId);
    }

    public BusinessCardSetVO businessCardGet() {
        LambdaQueryWrapper<BusinessCardConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BusinessCardConfig::getIsDelete, Boolean.FALSE);
        BusinessCardConfig businessCardConfig = getOne(wrapper);
        if(businessCardConfig == null) {
            return null;
        }
        BusinessCardSetVO businessCardSetVO = new BusinessCardSetVO();
        businessCardSetVO.setAppoint(businessCardConfig.getAppoint());
        businessCardSetVO.setPrice(businessCardConfig.getPrice());
        businessCardSetVO.setId(businessCardConfig.getId());
        return businessCardSetVO;
    }
}
